
#undef BOOST_TEST_DYN_LINK
#undef BOOST_TEST_MAIN
#undef BOOST_TEST_MODULE //TestModel2Cpp
#include <boost/test/unit_test.hpp>

#include <iostream>

#include "dataModel/Controller.hpp"

using namespace dataModel;


BOOST_AUTO_TEST_SUITE( TestingDataModelling )


BOOST_AUTO_TEST_CASE( testDirectOperations )
{
	std::cout << "testDirectOperations start" << std::endl;
	Controller _c;
	std::cout << "testDirectOperations +_c" << std::endl;
	CommParams _cp1;
	_cp1.setEmail("me@there.com");
	DataContainer _d("First ave., 13", "Nowhere", "someone", 99931);
	_d.setCommParams(_cp1);
	std::cout << "testDirectOperations +_d" << std::endl;
	_c.addData(_d);
	std::cout << "testDirectOperations +_c.addData" << std::endl;
	DataContainer _d2 = _d;
	std::vector<std::string> _tels;
	_tels.push_back("0949390003");
	_tels.push_back("abcdefghij");
	CommParams _cp2;
	_cp2.setEmail("another@brick.wall");
	_cp2.setPhones(_tels);
	_d2.setCommParams( _cp2 );
	_c.addData(_d2);
	BOOST_REQUIRE_EQUAL( _d.getCity(), "Nowhere" );
	BOOST_REQUIRE_EQUAL( _d2.getCity(), "Nowhere" );
	std::cout << "testDirectOperations +_d2" << std::endl;
	BOOST_REQUIRE( !(_c.findDataByName("somebody") == _d) );
	std::cout << "testDirectOperations _c.findDataByName" << std::endl;
	BOOST_REQUIRE_EQUAL( _d.getName(), "someone" );
	BOOST_REQUIRE( _c.findDataByName("someone") == _d );
	std::cout << "testDirectOperations _c.findDataByName" << std::endl;
}

BOOST_AUTO_TEST_CASE( testSwap_CommParams )
{
	CommParams _c1, _c2;
	_c1.setEmail("calling.c1@there.com");
	_c2.setEmail("calling.c2@there.com");
	std::swap(_c1, _c2);
	BOOST_REQUIRE_EQUAL( _c1.getEmail(), "calling.c2@there.com" );
	BOOST_REQUIRE_EQUAL( _c2.getEmail(), "calling.c1@there.com" );
}

BOOST_AUTO_TEST_CASE( testSwap_DataContainer )
{
	DataContainer _d1("Addr1", "City1", "Name1", 11111);
	_d1.addSale(101.0);
	DataContainer _d2("Addr2", "City2", "Name2", 22222);
	_d2.addSale(202.0);
	std::swap(_d1, _d2);
	// this is constant and cannot be swapped
	BOOST_REQUIRE_EQUAL( _d1.getCity(), "City1" );
	BOOST_REQUIRE_EQUAL( _d2.getCity(), "City2" );
	// this is swapped
	BOOST_REQUIRE_EQUAL( _d1.getRevenue(), 202.0 );
	BOOST_REQUIRE_EQUAL( _d2.getRevenue(), 101.0 );
}

BOOST_AUTO_TEST_SUITE_END()

